/*
=============================================
 Author:
 Student id:
 Description:
 Date:
=============================================
*/
#include <stdio.h>
void task6(void) {
  printf("\n Output of task6:\n");
  int value1, value2, sum;
  value1 = 15;
  value2 = 30;
  sum = value1 + value2;
  printf("The sum of %d and %d is %d\n", value1, value2, sum);
  return;

  /*Put your outputs here.
  1.
  2.
  3.
  4.
  */
}

void task7(void) {
  printf("\n Output of task7:\n");

  // note that the answer is not unique!
  char spaces[5] = {0};
  spaces[0] = 32; // ASCII code for space
  spaces[1] = 32;
  spaces[2] = 32;
  spaces[3] = 32;
  spaces[4] = '\0';

  printf("H%se%sl%sl%so", spaces, spaces, spaces, spaces);
  return;
}

void task8(void) {
  printf("\n Output of task8:\n");

  int percentage, x;
  char ch1, ch2;
  scanf("%d%c%c%d", &percentage, &ch1, &ch2, &x);
  // print each variable
  printf("percnetage is %d, ch1 is %c, ch2 is %c, x is %d\n", percentage, ch1,
         ch2, x);

  printf("%d%% %c%c %d is %f\n", percentage, ch1, ch2, x,
         1.0 * x * percentage / 100);
  return;
  //   The value of x is 0 because the input you provided ("10 of100") doesn't
  //   match the format expected by the scanf statement. Let's break it down:
  // What's happening:
  // The format string %d%c%c%d expects:
  // An integer (%d) for percentage
  // A character (%c) for ch1
  // Another character (%c) for ch2
  // Another integer (%d) for x
  // When you input "10 of100", here's how scanf processes it:
  // 10 is read into percentage
  // The space character (' ') is read into ch1
  // The character o is read into ch2
  // The next part of the input is f100, but %d expects an integer. Since f is
  // not part of an integer, the conversion fails, and x remains uninitialized
  // Why x appears as 0:
  // In C, automatic variables (like x in this case) don't have a default
  // initialization. Their initial value is indeterminate (whatever was in that
  // memory location before). However, in practice, you might see x as 0 for
  // these reasons: The memory location where x is stored happened to contain 0
  // before the program started Some compilers might zero-initialize automatic
  // variables in debug mode But strictly speaking, using an uninitialized
  // automatic variable is undefined behavior. The value could be anything.

  /*
  Put outputs and explanations here.
  1.10of100:
  2.10 of100:
  3.10 of 100:
  */
}

void task9(void) {
  printf("\n Output of task9:\n");
  int i;
  char ch;
  float j;
  scanf("%d %f %c", &i, &j, &ch);
  printf("%d is the ASCII code of '%c'.\n", ch, ch);
  printf("The value of i is %d.", i);
  printf("The value of j is %.1f.", j);
  return;
}

void task10(void) {
  printf("\n Output of task10:\n");
  int m, n;
  scanf("%d %d", &m, &n);

  int sum = m + n;
  int sub = m - n;
  int prod = m * n;
  int quot = m / n;
  int rem = m % n;
  float float_quot = (float)m / n;

  printf("%d + %d = %d\n", m, n, sum);
  printf("%d - %d = %d\n", m, n, sub);
  printf("%d * %d = %d\n", m, n, prod);
  printf("%d / %d = %d\n", m, n, quot);
  printf("%d %% %d = %d\n", m, n, rem);
  printf("float(%d) / %d = %.6f\n", m, n, float_quot);
  return;
}

int main() {
  int choice;
  char ch;
  do {
    // Display menu options
    printf("\nSelect a task to run:\n");
    printf("6. Task6\n7. Task7\n8. Task8\n9. Task9\n10. Task10\n");
    printf("Press Enter to terminate\n");
    printf("Enter your choice (6-10 or Enter to quit): ");

    // Read user's choice
    if (scanf("%d", &choice) == 1) {
      // Clear the input buffer
      while ((ch = getchar()) != '\n' && ch != EOF)
        ;

      // Switch-case to handle the choice
      switch (choice) {
      case 6:
        task6();
        break;
      case 7:
        task7();
        break;
      case 8:
        task8();
        break;
      case 9:
        task9();
        break;
      case 10:
        task10();
        break;
      default:
        printf("Invalid selection. Please choose a number between 6 and 10.\n");
      }
    } else {
      // User pressed Enter without entering a number
      // Clear the input buffer
      while ((ch = getchar()) != '\n' && ch != EOF)
        ;
      break; // Exit the loop
    }

  } while (1);

  printf("Program terminated.\n");
  return 0;
}